#!bin/bash

func()
{
now_date=`date "+%Y-%m-%d-%H"`
success_flag_timetamp=''
yest_date=`date -d "1 hour ago" "+%Y-%m-%d-%H"`
echo "分区日期："+$yest_date

while [ -z "$success_flag_timetamp" ]
do
    a=$((hdfs dfs -stat "%Y" hdfs://yl-bg-hdp/dw/hive/jms_dwd.db/external/dwd_tab_barscan_deliver_base_hi/dt=$yest_date/ 1>&2) 2>&1 1>/dev/null)
    echo $a
    result=$(echo $a | grep "No such file or directory")
    if [[ $result != '' ]]
    then
       echo "文件未生成"
       sleep 1m
       continue
    fi
    success_flag_timetamp=`hdfs dfs -stat "%Y" hdfs://yl-bg-hdp/dw/hive/jms_dwd.db/external/dwd_tab_barscan_deliver_base_hi/dt=$yest_date/`
    echo "检查路径：" +hdfs://yl-bg-hdp/dw/hive/jms_dwd.db/external/dwd_tab_barscan_deliver_base_hi/dt=$yest_date/
    echo $success_flag_timetamp
    timestmaps_check_noformat=`expr $success_flag_timetamp / 1000`
    timestmaps_check=`date -d@$timestmaps_check_noformat "+%Y-%m-%d %H:%M:%S"`
    echo "循环检查分区时间：" +$timestmaps_check
  sleep 1m
done

success_flag=`expr $success_flag_timetamp / 1000`
flag_date=`date -d@$success_flag "+%Y-%m-%d-%H"`
echo "当前时间：" $now_date
echo "更新分区时间：" $flag_date
echo "============================"
}

while [ $now_date != $flag_date ]
do
  #sleep 1m
  func
done
echo "success~~~"